#include "qalignmentproperty.h"

#include "qenumproperty.h"


#include "../../libs/sharedLib/qcommonstruct.h"
#include "../../libs/sharedLib/qeditorlabel.h"


QAlignmentProperty::QAlignmentProperty(SHAREDLIB::QAbstractProperty *parent):
        SHAREDLIB::QAbstractProperty(parent)
{
    m_horizonta=new QEnumProperty(this);
    m_horizonta->setAttribute("property_name",tr("Horizonta"));
    m_horizonta->setAttribute("name","Horizonta");
    ComboItems items;
    tagComboItem item;
    item.m_text=tr("AlignLeft");
    item.m_value=Qt::AlignLeft;
    items.append(item);

    item.m_text=tr("AlignRight");
    item.m_value=Qt::AlignRight;
    items.append(item);

    item.m_text=tr("AlignHCenter");
    item.m_value=Qt::AlignHCenter;
    items.append(item);
    QVariant v;
    v.setValue<ComboItems>(items);
    m_horizonta->setAttribute("items",v);

    m_vertical=new QEnumProperty(this);
    m_vertical->setAttribute("property_name",tr("Vertical"));
    m_vertical->setAttribute("name","Vertical");

    items.clear();
    item.m_text=tr("AlignTop");
    item.m_value=Qt::AlignTop;
    items.append(item);

    item.m_text=tr("AlignBottom");
    item.m_value=Qt::AlignBottom;
    items.append(item);

    item.m_text=tr("AlignVCenter");
    item.m_value=Qt::AlignVCenter;
    items.append(item);

    v.setValue<ComboItems>(items);
    m_vertical->setAttribute("items",v);
}

QWidget* QAlignmentProperty::getEditor()
{
    return new SHAREDLIB::QEditorLabel(this);
}

QString QAlignmentProperty::valueText()
{
    QString str;
    str=m_horizonta->valueText()+" | "+m_vertical->valueText();
    return str;
}

void QAlignmentProperty::setValue(const QVariant &value)
{
    int align=value.toInt();
    m_horizonta->setValue(align & Qt::AlignHorizontal_Mask);
    m_vertical->setValue(align & Qt::AlignVertical_Mask);
    SHAREDLIB::QAbstractProperty::setValue(value);

}

void QAlignmentProperty::subPropertyChanged(const QVariant &)
{
    int align;
    align=m_horizonta->getValue().toInt() | m_vertical->getValue().toInt();
    setValue(align);
}
